package com.sinosoft.vaccinetoai.server.business.login.service.impl;

import com.sinosoft.vaccinetoai.security.shiro.SSOAuthenticationToken;
import com.sinosoft.vaccinetoai.server.business.base.server.LoginServer;
import com.sinosoft.vaccinetoai.server.business.base.server.model.LoginResModel;
import com.sinosoft.vaccinetoai.server.business.login.io.SSOLoginIO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinosoft.vaccinetoai.server.business.login.vo.LoginVO;
import com.sinosoft.vaccinetoai.server.business.login.service.ILoginService;

/**
 * @ClassName: LoginServiceImpl
 * @ClassNameExplain: 
 * @Description: 用户登录Service Impl
 * @author xzh
 * @date 2025年06月24日 09:02
 */
@Slf4j
@Service("LoginService")
public class LoginServiceImpl implements ILoginService {

	@Autowired
	private LoginServer loginServer;

	@Override
	public LoginVO ssoLogin(SSOLoginIO io) throws Exception {
        String ssoToken = io.getToken();
		SSOAuthenticationToken ssoAuthenticationToken = new SSOAuthenticationToken(ssoToken);
		LoginResModel loginResModel = loginServer.login(ssoAuthenticationToken);
		//赋值
		return buildLoginVO(loginResModel);
	}

	/**
	 * 通过登录model构建返回信息
	 * @param loginResModel
	 * @return
	 */
	private LoginVO buildLoginVO(LoginResModel loginResModel) {
		LoginVO vo = new LoginVO();
		vo.setUserId(loginResModel.getUserId());
		vo.setExpire(loginResModel.getExpire());
		vo.setToken(loginResModel.getToken());
		vo.setOrgSSO(loginResModel.getOrgSSO());
		return vo;
	}

}